package org.zhaozhen.quartz.job;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.zhaozhen.order.domain.AdoptOrder;
import org.zhaozhen.order.service.IAdoptOrderService;
import org.zhaozhen.pet.mapper.PetMapper;
import org.zhaozhen.pet.service.IPetService;
import org.zhaozhen.quartz.constant.JobTypeConstants;

import java.util.Map;

/**
 * 公共job业务抽象类
 *  这个类是在添加到quartz的时候 动态创建并交给容器管理
 */
public class MainJob implements Job{
    @Autowired
    private IAdoptOrderService adoptOrderService;
    @Autowired
    private IPetService petService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        Map<String,Object> map = (Map<String, Object>) jobDataMap.get("params");

        //拿到传递的业务类型
        String type = (String) map.get("type");// 不同的订单业务
        switch (type){
            case JobTypeConstants.TIME_OUT_ADOPT_LAST_PAY:{
                 //领养订单的支付超时取消
                //在得到业务类型下的订单号,执行业务逻辑
                Long orderId = (Long) map.get("orderId");// 不同的订单
                adoptOrderService.cancelByQuartz(orderId);
                AdoptOrder adoptOrder = adoptOrderService.queryById(orderId);
                break;
            }
            default:break;
        }


    }
}
